package com.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.GridView;

import com.adapter.base.ViewHolder;
import com.adapter.base.abslistview.CommonAdapter;
import com.util.R;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/7/8.
 */
public class DatePickerAcy extends BaseActivity {
    @Bind(R.id.gv_datePicker)
    GridView gv_datePicker;
    private Calendar calendar;
    private int month;
    private int firstDayOfMonthInWeek;

    private List<String> dateList;
  private BaseAdapter adapter;
    private List<String> weekList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.acy_date_picker);
        ButterKnife.bind(this);
        initData();
    }

    @Override
    protected void initData() {
        super.initData();
        dateList = new ArrayList<>();
        weekList = new ArrayList<>();
        weekList.add("日");
        weekList.add("一");
        weekList.add("二");
        weekList.add("三");
        weekList.add("四");
        weekList.add("五");
        weekList.add("六");
        dateList.addAll(weekList);
        for (int i = 1; i <= 31; i++) {
            dateList.add(i + "");
        }
        calendar = Calendar.getInstance();
        calendar.set(calendar.get(Calendar.YEAR), 6, 1); //传入的月份要-1,如查5月就传入4月
        firstDayOfMonthInWeek = calendar.get(Calendar.DAY_OF_WEEK);
        adapter=new CommonAdapter<String>(DatePickerAcy.this, R.layout.item_grid_view_date_picker, dateList) {
            @Override
            public void convert(ViewHolder holder, String s) {
                holder.setText(R.id.tv_date_itemGridViewDatePicker, s);
                if(s.equals("-1")){
                    holder.getView(R.id.tv_date_itemGridViewDatePicker).setVisibility(View.INVISIBLE);
                }
            }
        };
        gv_datePicker.setAdapter(adapter);
        if (firstDayOfMonthInWeek == 1) {

        } else {
            List<String> invaild = new ArrayList<>();
            for (int i = 0; i < firstDayOfMonthInWeek-1; i++) {
                invaild.add(-1+"");
            }
            List<String> tempList = new ArrayList<>();
            tempList.addAll(dateList);
            tempList.remove(0);
            tempList.remove(0);
            tempList.remove(0);
            tempList.remove(0);
            tempList.remove(0);
            tempList.remove(0);
            tempList.remove(0);
            dateList.clear();
            dateList.addAll(weekList);
            dateList.addAll(invaild);
            dateList.addAll(tempList);
            adapter.notifyDataSetChanged();
        }
    }
}
